﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace test.time.文件
{
    public partial class FormFileBase : Form
    {
        public FormFileBase()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DirectoryInfo dir = new DirectoryInfo(@"C:\Users\zr\Desktop\111");
            if (dir.Exists)
                dir.Delete(true);
            
            MessageBox.Show("ok");
        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            DirectoryInfo dir = new DirectoryInfo(@"C:\Users\zr\Desktop\111");
            if (!dir.Exists)
                dir.Create();
            dir = null;
            MessageBox.Show("ok");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DirectoryInfo dir = new DirectoryInfo(@"C:\Users\zr\Desktop\111");
            if (dir.Exists)
                dir.MoveTo(@"C:\Users\zr\Desktop\222");
            MessageBox.Show("ok");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DirectoryInfo dir = new DirectoryInfo(@"C:\Users\zr\Desktop\111");
            FileInfo[] a = null;
            if (dir.Exists)
            {
                a = dir.GetFiles(@"*.*");
            }
            string s = "";
            foreach (var item in a)
            {
                s += item.Name;
            }
            MessageBox.Show(s);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            DirectoryInfo dir = new DirectoryInfo(@"C:\Users\zr\Desktop\111");
            if (dir.Exists)
            {
                string strFile = @"C:\Users\zr\Desktop\111\1.txt";
                var f=File.Create(strFile);
                //var f = File.Create(strFile);
                f.Dispose();
                

            }
            MessageBox.Show("ok");
        }

        private void button9_Click(object sender, EventArgs e)
        {
            Encoding encode = Encoding.Default;
            StreamWriter sw = new StreamWriter(@"C:\Users\zr\Desktop\111\1.txt", false, encode);
            sw.Write("11111111");
            sw.Flush();
            sw.Close();
            MessageBox.Show("ok");

        }

        private void button8_Click(object sender, EventArgs e)
        {
            StreamReader sr = new StreamReader(@"C:\Users\zr\Desktop\111\1.txt");
            string temp = sr.ReadToEnd();
            sr.Dispose();
            MessageBox.Show(temp);
        }

        private void button10_Click(object sender, EventArgs e)
        {
            jisuan(@"C:\Users\zr\Desktop\111\");
            MessageBox.Show(sum.ToString());
        }

        int sum = 0;
        private void jisuan(string strin)
        {
            //string strin = @"C:\Users\zr\Desktop\111";
            DirectoryInfo d = new DirectoryInfo(strin);
            FileSystemInfo[] f = d.GetFileSystemInfos();
            foreach (FileSystemInfo i in f)
            {
                if (i is DirectoryInfo)
                {
                    jisuan(strin + i.Name + "\\");
                }
                else if (i is FileInfo)
                {
                    sum++;
                }
            }
            
        }

        private void button11_Click(object sender, EventArgs e)
        {
            string strFileName = "1.txt";
            string s=Path.GetExtension(strFileName);
            MessageBox.Show(s);
        }

        

    }
}
